package com.situ.controller.sal_chance;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.service.user.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.sal_chance.SalChanceService;
import com.situ.entity.sal_chance.SalChance;
import com.situ.util.*;


import java.util.List;

/**
 * SalChance的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class SalChanceController {

	/** SalChanceService服务 */
	@Autowired
	private SalChanceService salChanceService;
    @Autowired
    private SysUserService sysUserService;
	
	/**
	 * 查询所有SalChance数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/SalChance/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(SalChance value) {

		return ResponseData.ok().putDataValue("list",salChanceService.find(value));
	}
	
	/**
	 * 通过id查询SalChance数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SalChance/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",salChanceService.findOne(id));
	}
	
	/**
	 * 插入SalChance属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SalChance/save")
	public ResponseData save(SalChance value) {
		return ResponseData.ok().putDataValue("obj", salChanceService.saveNotNull(value));
	}
	
	/**
	 * 更新SalChance属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SalChance/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(SalChance value) {
		return ResponseData.ok().putDataValue("obj",salChanceService.updateNotNullById(value));
	}

	/**
	 * 通过id删除SalChance数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SalChance/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",salChanceService.deleteById(id));
	}


    //带分页的查询全部
@ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/SalChance/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(SalChance value,
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @RequestParam(defaultValue = "5",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);

        List<SalChance> list = salChanceService.find(value);

    PageInfo pageInfo = new PageInfo<SalChance>(list,5);

        return ResponseData.ok()
         .putDataValue("list", list)
        .putDataValue("pageInfo",pageInfo);
        }
        /*
        模糊高级查询带分页
         */
    @ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/SalChance/queryPage2", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage2(SalChance chance,
                                  @RequestParam(defaultValue = "1",required = false) int pageNum ,
                                  @RequestParam(defaultValue = "5",required = false) int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        List<SalChance> list = salChanceService.find1(chance);

        PageInfo pageInfo = new PageInfo<SalChance>(list,5);

        return ResponseData.ok()
                .putDataValue("pageInfo",pageInfo);
    }
/*
客户经理查询
 */
@RequestMapping(value = "/SalChance/queryById2", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryById2() {
     return ResponseData.ok().putDataValue("obj",sysUserService.findOne2());
    }
}
